package r4p_gui;

import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.UIManager;

import r4p.GUI.LanguageLoader;
/*
 * MainWindow.java
 *
 * Created on 31 de agosto de 2008, 22:00
 */
import javax.swing.UnsupportedLookAndFeelException;
import r4p.modules.communications.bluetooth.Messenger;
import r4p.modules.sensors.Info;
import r4p.modules.servomotors.Sequence;



/**
 *
 * @author  nemesis
 */
public class MainWindow extends javax.swing.JFrame {

    //controls:
    boolean[] buttonStatus;
    Messenger messenger;
    Info infoParser;
    boolean connected;
    
    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
	// controls init:
	buttonStatus = new boolean[6];
	for (int i = 0; i < buttonStatus.length; i++) {
	    buttonStatus[i] = false;
	}
	
	this.messenger = new Messenger("0006660066AC", "btspp", 1);
	this.connected = false;
	
//	while (true) {
//	    if (this.connected) {
//		String aux = this.messenger.receive();
//		this.infoParser.parseString(aux);
//		int[] auxSensorValues = this.infoParser.getSensorValues();
//		this.sensorsPanel.setValues(auxSensorValues[0], auxSensorValues[1], auxSensorValues[2], auxSensorValues[3]);
//	    }
//	}
    }
    
    public void relanguage(ArrayList<String> controls, ArrayList<String> comms, ArrayList<String> lang, ArrayList<String> sensors, ArrayList<String> seq) {
	//controls:
	this.controlButtonSendCommand.setText(controls.get(1));
	this.controlButtonFunction_EmergencyStop.setText(controls.get(0));
	this.controlButtonFunction_0.setText(controls.get(2));
	this.controlButtonFunction_1.setText(controls.get(3));
	this.conrolButtonFunction_2.setText(controls.get(4));
	this.controlButtonFunction_3.setText(controls.get(5));
	this.controlButtonFunction_4.setText(controls.get(6));
	//sensors:
	this.sensorsPanel.reLanguage(sensors.get(0), sensors.get(1), sensors.get(2), sensors.get(3));
	//sequences:
	this.seqButtonBack.setText(seq.get(0));
	this.seqButtonForward.setText(seq.get(1));
	this.seqButtonLoad.setText(seq.get(2));
	this.seqButtonPlay.setText(seq.get(3));
	this.seqButtonReset.setText(seq.get(4));
	this.seqButtonSave.setText(seq.get(5));
	this.seqButtonSend.setText(seq.get(6));
	//comms:
	this.commsApplyButton.setText(comms.get(16));
	this.commsResetButton.setText(comms.get(17));
	this.commsTestButton.setText(comms.get(18));
	this.confCommsPanel1.relanguage(comms);
	//lang:
	this.langApplyButton.setText(lang.get(6));
	this.confLangsPanel1.relanguage(lang);
	//about:
	
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sensorsPanel = new r4p_gui.SensorsPanel();
        graphPanel = new javax.swing.JPanel();
        tabsPanel = new javax.swing.JTabbedPane();
        movSeqEditorPanel = new javax.swing.JPanel();
        sequenceEditorPanel1 = new r4p_gui.SequenceEditorPanel();
        seqButtonBack = new javax.swing.JButton();
        seqButtonLoad = new javax.swing.JButton();
        seqButtonReset = new javax.swing.JButton();
        seqButtonPlay = new javax.swing.JButton();
        seqButtonForward = new javax.swing.JButton();
        seqButtonSend = new javax.swing.JButton();
        seqButtonSave = new javax.swing.JButton();
        confCommsPanel = new javax.swing.JPanel();
        confCommsPanel1 = new r4p_gui.ConfCommsPanel();
        commsApplyButton = new javax.swing.JButton();
        commsResetButton = new javax.swing.JButton();
        commsTestButton = new javax.swing.JButton();
        confLangPanel = new javax.swing.JPanel();
        confLangsPanel1 = new r4p_gui.ConfLangsPanel();
        langApplyButton = new javax.swing.JButton();
        aboutPanel = new javax.swing.JPanel();
        controlsPanel = new javax.swing.JPanel();
        controlButtonLeft = new javax.swing.JButton();
        controlButtonSendCommand = new javax.swing.JButton();
        controlLabelState = new javax.swing.JLabel();
        controlButtonFunction_0 = new javax.swing.JButton();
        controlButtonBackward = new javax.swing.JButton();
        controlButtonFunction_EmergencyStop = new javax.swing.JButton();
        controlButtonFunction_1 = new javax.swing.JButton();
        conrolButtonFunction_2 = new javax.swing.JButton();
        controlButtonForward = new javax.swing.JButton();
        controlButtonFunction_3 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        controlTextCommand = new javax.swing.JTextPane();
        controlButtonFunction_4 = new javax.swing.JButton();
        controlButtonRight = new javax.swing.JButton();
        connectingPeopleButton = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dominus - R4P Remote Control Application");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        graphPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Servomotors Graph Representation", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 0, 10))); // NOI18N

        javax.swing.GroupLayout graphPanelLayout = new javax.swing.GroupLayout(graphPanel);
        graphPanel.setLayout(graphPanelLayout);
        graphPanelLayout.setHorizontalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 652, Short.MAX_VALUE)
        );
        graphPanelLayout.setVerticalGroup(
            graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 317, Short.MAX_VALUE)
        );

        seqButtonBack.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/seqBck.png")); // NOI18N

        seqButtonLoad.setText("Load");
        seqButtonLoad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                seqButtonLoadMouseClicked(evt);
            }
        });

        seqButtonReset.setText("Reset");
        seqButtonReset.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                seqButtonResetMouseClicked(evt);
            }
        });

        seqButtonPlay.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/seqPlay.png")); // NOI18N

        seqButtonForward.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/seqFwd.png")); // NOI18N
        seqButtonForward.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seqButtonForwardActionPerformed(evt);
            }
        });

        seqButtonSend.setText("Send");

        seqButtonSave.setText("Save");
        seqButtonSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                seqButtonSaveMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout movSeqEditorPanelLayout = new javax.swing.GroupLayout(movSeqEditorPanel);
        movSeqEditorPanel.setLayout(movSeqEditorPanelLayout);
        movSeqEditorPanelLayout.setHorizontalGroup(
            movSeqEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(movSeqEditorPanelLayout.createSequentialGroup()
                .addComponent(sequenceEditorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(movSeqEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(seqButtonReset, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                    .addComponent(seqButtonSend, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                    .addComponent(seqButtonSave, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                    .addComponent(seqButtonLoad, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                    .addGroup(movSeqEditorPanelLayout.createSequentialGroup()
                        .addComponent(seqButtonBack)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonPlay)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonForward)))
                .addGap(431, 431, 431))
        );
        movSeqEditorPanelLayout.setVerticalGroup(
            movSeqEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(movSeqEditorPanelLayout.createSequentialGroup()
                .addGroup(movSeqEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sequenceEditorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(movSeqEditorPanelLayout.createSequentialGroup()
                        .addGap(105, 105, 105)
                        .addGroup(movSeqEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(seqButtonForward)
                            .addComponent(seqButtonPlay)
                            .addComponent(seqButtonBack))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonLoad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonSend)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(seqButtonReset)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tabsPanel.addTab("Movement Sequence Editor", movSeqEditorPanel);

        commsApplyButton.setText("Apply Configuration");

        commsResetButton.setText("Reset Configuration");

        commsTestButton.setText("Test Configuration");

        javax.swing.GroupLayout confCommsPanelLayout = new javax.swing.GroupLayout(confCommsPanel);
        confCommsPanel.setLayout(confCommsPanelLayout);
        confCommsPanelLayout.setHorizontalGroup(
            confCommsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(confCommsPanelLayout.createSequentialGroup()
                .addComponent(confCommsPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(confCommsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(commsApplyButton)
                    .addComponent(commsResetButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(commsTestButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(705, Short.MAX_VALUE))
        );
        confCommsPanelLayout.setVerticalGroup(
            confCommsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(confCommsPanelLayout.createSequentialGroup()
                .addGroup(confCommsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(confCommsPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(confCommsPanelLayout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(commsApplyButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(commsResetButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(commsTestButton)))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        tabsPanel.addTab("Communications Configuration", confCommsPanel);

        langApplyButton.setText("Apply Configuration");
        langApplyButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                langApplyButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout confLangPanelLayout = new javax.swing.GroupLayout(confLangPanel);
        confLangPanel.setLayout(confLangPanelLayout);
        confLangPanelLayout.setHorizontalGroup(
            confLangPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(confLangPanelLayout.createSequentialGroup()
                .addComponent(confLangsPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(langApplyButton)
                .addContainerGap(631, Short.MAX_VALUE))
        );
        confLangPanelLayout.setVerticalGroup(
            confLangPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(confLangPanelLayout.createSequentialGroup()
                .addGroup(confLangPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(confLangPanelLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(confLangsPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(confLangPanelLayout.createSequentialGroup()
                        .addGap(128, 128, 128)
                        .addComponent(langApplyButton)))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        tabsPanel.addTab("Language Configuration", confLangPanel);

        javax.swing.GroupLayout aboutPanelLayout = new javax.swing.GroupLayout(aboutPanel);
        aboutPanel.setLayout(aboutPanelLayout);
        aboutPanelLayout.setHorizontalGroup(
            aboutPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        aboutPanelLayout.setVerticalGroup(
            aboutPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 395, Short.MAX_VALUE)
        );

        tabsPanel.addTab("About", aboutPanel);

        controlsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Robot Controls", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 0, 10))); // NOI18N

        controlButtonLeft.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/back.png")); // NOI18N
        controlButtonLeft.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonLeftMouseClicked(evt);
            }
        });

        controlButtonSendCommand.setText("Send");
        controlButtonSendCommand.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonSendCommandMouseClicked(evt);
            }
        });

        controlLabelState.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        controlLabelState.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        controlLabelState.setText("Robot Current State");

        controlButtonFunction_0.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/init-base.png")); // NOI18N
        controlButtonFunction_0.setText("Init to base position");
        controlButtonFunction_0.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        controlButtonFunction_0.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonFunction_0MouseClicked(evt);
            }
        });

        controlButtonBackward.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/down.png")); // NOI18N
        controlButtonBackward.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonBackwardMouseClicked(evt);
            }
        });

        controlButtonFunction_EmergencyStop.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/emergency-stop.png")); // NOI18N
        controlButtonFunction_EmergencyStop.setText("Emergency STOP!");
        controlButtonFunction_EmergencyStop.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        controlButtonFunction_EmergencyStop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonFunction_EmergencyStopMouseClicked(evt);
            }
        });

        controlButtonFunction_1.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/base-2patas.png")); // NOI18N
        controlButtonFunction_1.setText("Biped Position");
        controlButtonFunction_1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        controlButtonFunction_1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonFunction_1MouseClicked(evt);
            }
        });

        conrolButtonFunction_2.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/demo-icon.png")); // NOI18N
        conrolButtonFunction_2.setText("Demo 1");
        conrolButtonFunction_2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        conrolButtonFunction_2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                conrolButtonFunction_2MouseClicked(evt);
            }
        });

        controlButtonForward.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/go-up.png")); // NOI18N
        controlButtonForward.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonForwardMouseClicked(evt);
            }
        });

        controlButtonFunction_3.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/demo-icon.png")); // NOI18N
        controlButtonFunction_3.setText("Demo 2");
        controlButtonFunction_3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        controlButtonFunction_3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonFunction_3MouseClicked(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jScrollPane1.setViewportView(controlTextCommand);

        controlButtonFunction_4.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/demo-icon.png")); // NOI18N
        controlButtonFunction_4.setText("Demo 3");
        controlButtonFunction_4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        controlButtonFunction_4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonFunction_4MouseClicked(evt);
            }
        });

        controlButtonRight.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/forward.png")); // NOI18N
        controlButtonRight.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                controlButtonRightMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout controlsPanelLayout = new javax.swing.GroupLayout(controlsPanel);
        controlsPanel.setLayout(controlsPanelLayout);
        controlsPanelLayout.setHorizontalGroup(
            controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(controlLabelState, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(controlButtonFunction_EmergencyStop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(controlsPanelLayout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(controlButtonForward)
                                .addGroup(controlsPanelLayout.createSequentialGroup()
                                    .addComponent(controlButtonLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(controlButtonBackward)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(controlButtonRight))
                        .addComponent(jScrollPane1))
                    .addComponent(controlButtonSendCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(controlButtonFunction_4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(controlButtonFunction_3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(conrolButtonFunction_2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(controlButtonFunction_1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(controlButtonFunction_0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        controlsPanelLayout.setVerticalGroup(
            controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlsPanelLayout.createSequentialGroup()
                .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, controlsPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(controlButtonForward)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(controlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(controlButtonLeft)
                            .addComponent(controlButtonBackward)
                            .addComponent(controlButtonRight))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controlButtonFunction_EmergencyStop)
                        .addGap(18, 18, 18)
                        .addComponent(controlLabelState)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controlButtonSendCommand))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, controlsPanelLayout.createSequentialGroup()
                        .addComponent(controlButtonFunction_0)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controlButtonFunction_1)
                        .addGap(18, 18, 18)
                        .addComponent(conrolButtonFunction_2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controlButtonFunction_3, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(controlButtonFunction_4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        connectingPeopleButton.setText("Connect");
        connectingPeopleButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                connectingPeopleButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(controlsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sensorsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(tabsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1354, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(connectingPeopleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(sensorsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(controlsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(connectingPeopleButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void seqButtonLoadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seqButtonLoadMouseClicked
    // TODO add your handling code here:
    JFileChooser fileChooser = new JFileChooser();
    int returnVal = fileChooser.showOpenDialog(this);
    
    if (returnVal == JFileChooser.APPROVE_OPTION) {
	//loading sequence:
	this.sequenceEditorPanel1.sequence.setFilename(fileChooser.getSelectedFile().toString());
	this.sequenceEditorPanel1.sequence.load();
    }
}//GEN-LAST:event_seqButtonLoadMouseClicked

private void seqButtonResetMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seqButtonResetMouseClicked
    // TODO add your handling code here:
    int[] auxValues = new int[12];
    for (int i = 0; i < 12; i++) {
	auxValues[i] = 0;
    }
    this.sequenceEditorPanel1.setValues(auxValues);
    this.sequenceEditorPanel1.sequence = new Sequence();
    this.sequenceEditorPanel1.setTime(0);
}//GEN-LAST:event_seqButtonResetMouseClicked

private void seqButtonForwardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seqButtonForwardActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_seqButtonForwardActionPerformed

private void controlButtonLeftMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonLeftMouseClicked
//left button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonLeftMouseClicked

private void controlButtonSendCommandMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonSendCommandMouseClicked
//send button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonSendCommandMouseClicked

private void controlButtonFunction_0MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonFunction_0MouseClicked
//init to base button:
    if (this.buttonStatus[0]) {
	this.controlButtonFunction_0.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/init-base.png"));
	this.buttonStatus[0] = false;
    } else {
	this.controlButtonFunction_0.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/base-init.png"));
	this.buttonStatus[0] = true;
    }
}//GEN-LAST:event_controlButtonFunction_0MouseClicked

private void controlButtonBackwardMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonBackwardMouseClicked
//backward button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonBackwardMouseClicked

private void controlButtonFunction_EmergencyStopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonFunction_EmergencyStopMouseClicked
//emergency stop button:
    if (this.buttonStatus[1]) {
	this.controlButtonFunction_EmergencyStop.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/continue.png"));
	this.buttonStatus[1] = false;
    } else {
	this.controlButtonFunction_EmergencyStop.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/emergency-stop.png"));
	this.buttonStatus[1] = true;
    }
}//GEN-LAST:event_controlButtonFunction_EmergencyStopMouseClicked

private void controlButtonFunction_1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonFunction_1MouseClicked
//biped position button:
    if (this.buttonStatus[2]) {
	this.controlButtonFunction_1.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/2patas-base.png"));
	this.buttonStatus[2] = false;
    } else {
	this.controlButtonFunction_1.setIcon(new javax.swing.ImageIcon("/home/nemesis/NetBeansProjects/R4P_gui/icons/base-2patas.png"));
	this.buttonStatus[2] = true;
    }
}//GEN-LAST:event_controlButtonFunction_1MouseClicked

private void conrolButtonFunction_2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_conrolButtonFunction_2MouseClicked
//demo 1 button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_conrolButtonFunction_2MouseClicked

private void controlButtonForwardMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonForwardMouseClicked
//forward button:
}//GEN-LAST:event_controlButtonForwardMouseClicked

private void controlButtonFunction_3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonFunction_3MouseClicked
//demo 2 button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonFunction_3MouseClicked

private void controlButtonFunction_4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonFunction_4MouseClicked
//demo 3 button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonFunction_4MouseClicked

private void controlButtonRightMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_controlButtonRightMouseClicked
//right button:
    this.messenger.send("{"+0+"}");
}//GEN-LAST:event_controlButtonRightMouseClicked

private void langApplyButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_langApplyButtonMouseClicked
    // TODO add your handling code here:
    
    LanguageLoader ll = new LanguageLoader("/home/nemesis/NetBeansProjects/R4P_gui/config/langs/" + this.confLangsPanel1.getSelectedLanguage());
    
//    ArrayList<String> controls = ll.getConf_controls();
//    ArrayList<String> sensors = ll.getConf_sensors();
//    ArrayList<String> seq = ll.getConf_seq();
    ArrayList<String> comms = ll.getConf_comms();
    ArrayList<String> lang = ll.getConf_lang();
    
//    for (int i = 0; i < 20; i++) {
//	controls.add("control_" + i);
////	comms.add("comms_" + i);
////	lang.add("lang_" + i);
//	sensors.add("sensor_" + i);
////	seq.add("seq_" + i);
//    }
    
//    this.relanguage(controls, comms, lang, sensors, seq);
}//GEN-LAST:event_langApplyButtonMouseClicked

private void seqButtonSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seqButtonSaveMouseClicked
    // TODO add your handling code here:
    JFileChooser fileChooser = new JFileChooser();
    int returnVal = fileChooser.showSaveDialog(this);
    
    if (returnVal == JFileChooser.APPROVE_OPTION) {
	//saving sequence:
	this.sequenceEditorPanel1.sequence.setFilename(fileChooser.getSelectedFile().toString());
	this.sequenceEditorPanel1.sequence.save();
    }
}//GEN-LAST:event_seqButtonSaveMouseClicked

private void connectingPeopleButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_connectingPeopleButtonMouseClicked
    // TODO add your handling code here:
    // mirar si está on/off
    // pillar datos de la configuración
    // conectar
    this.messenger.connect();
    this.connected = true;
    String init = this.messenger.receive();
    this.infoParser.parseString(init);
    boolean[] sensorState = this.infoParser.getSensorsState();
    this.sensorsPanel.setStates(sensorState[0], sensorState[1], sensorState[2], sensorState[3]);
    // pillar secuencia de inicio y setear los sensores
    // error --> popup
}//GEN-LAST:event_connectingPeopleButtonMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
	try {
	    // Set cross-platform Java L&F (also called "Metal")
	    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	}
	catch (UnsupportedLookAndFeelException e) {
	   // handle exception
	}
	catch (ClassNotFoundException e) {
	   // handle exception
	}
	catch (InstantiationException e) {
	   // handle exception
	}
	catch (IllegalAccessException e) {
	   // handle exception
	}
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainWindow().setVisible(true);
		System.out.println("DOMINUS ALPHA SYSTEM STARTED!!!");
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aboutPanel;
    private javax.swing.JButton commsApplyButton;
    private javax.swing.JButton commsResetButton;
    private javax.swing.JButton commsTestButton;
    private javax.swing.JPanel confCommsPanel;
    private r4p_gui.ConfCommsPanel confCommsPanel1;
    private javax.swing.JPanel confLangPanel;
    private r4p_gui.ConfLangsPanel confLangsPanel1;
    private javax.swing.JToggleButton connectingPeopleButton;
    private javax.swing.JButton conrolButtonFunction_2;
    private javax.swing.JButton controlButtonBackward;
    private javax.swing.JButton controlButtonForward;
    private javax.swing.JButton controlButtonFunction_0;
    private javax.swing.JButton controlButtonFunction_1;
    private javax.swing.JButton controlButtonFunction_3;
    private javax.swing.JButton controlButtonFunction_4;
    private javax.swing.JButton controlButtonFunction_EmergencyStop;
    private javax.swing.JButton controlButtonLeft;
    private javax.swing.JButton controlButtonRight;
    private javax.swing.JButton controlButtonSendCommand;
    private javax.swing.JLabel controlLabelState;
    private javax.swing.JTextPane controlTextCommand;
    private javax.swing.JPanel controlsPanel;
    private javax.swing.JPanel graphPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton langApplyButton;
    private javax.swing.JPanel movSeqEditorPanel;
    private r4p_gui.SensorsPanel sensorsPanel;
    private javax.swing.JButton seqButtonBack;
    private javax.swing.JButton seqButtonForward;
    private javax.swing.JButton seqButtonLoad;
    private javax.swing.JButton seqButtonPlay;
    private javax.swing.JButton seqButtonReset;
    private javax.swing.JButton seqButtonSave;
    private javax.swing.JButton seqButtonSend;
    private r4p_gui.SequenceEditorPanel sequenceEditorPanel1;
    private javax.swing.JTabbedPane tabsPanel;
    // End of variables declaration//GEN-END:variables

}
